﻿using System;
using System.Collections.Generic;

namespace 超市系统
{
    internal class Warehouse
    {
        //创建货架-存储货物
        private static List<List<Commodity>> goods = new List<List<Commodity>>();

        /// <summary>
        /// 构造函数添加货架
        /// </summary>
        public Warehouse()
        {
            goods.Add(new List<Commodity>());  //华硕
            goods.Add(new List<Commodity>());  //香蕉
            goods.Add(new List<Commodity>());  //大米
        }

        /// <summary>
        /// 进货
        /// </summary>
        /// <param name="strType">货物类型</param>
        /// <param name="count">货物数量</param>
        public void GetPros(string strType, int count)
        {
            for (int i = 0; i < count; i++)
            {
                switch (strType)
                {
                    case "ausu":
                        goods[0].Add(new Ausu(Guid.NewGuid().ToString(), 5999, "败家之眼"));
                        break;

                    case "banana":
                        goods[1].Add(new Banana(Guid.NewGuid().ToString(), 10, "香蕉"));
                        break;

                    case "rice":
                        goods[2].Add(new Ausu(Guid.NewGuid().ToString(), 3, "大米"));
                        break;
                }
            }
        }

        /// <summary>
        /// 提取货物
        /// </summary>
        /// <param name="strType">货物类型</param>
        /// <param name="count">货物数量</param>
        /// <returns></returns>
        public Commodity[] QutPros(string strType, int count)
        {
            Commodity[] pros = new Commodity[count];
            for (int i = 0; i < pros.Length; i++)
            {
                switch (strType)
                {
                    case "ausu":
                        if (goods[0].Count == 0)
                            Console.WriteLine("华硕没有了");
                        pros[i] = goods[0][0];
                        goods[0].RemoveAt(0);
                        break;

                    case "banana":
                        if (goods[1].Count == 0)
                            Console.WriteLine("香蕉没有了");
                        pros[i] = goods[1][0];
                        goods[1].RemoveAt(0);
                        break;

                    case "rice":
                        if (goods[2].Count == 0)
                            Console.WriteLine("大米没有了");
                        pros[i] = goods[2][0];
                        goods[2].RemoveAt(0);
                        break;
                }
            }
            return pros;
        }

        public void ShowPros()
        {
            foreach (var item in goods)
            {
                Console.WriteLine("我们超市有：{0}\t{1}元/{2}", item[0].Name, item[0].Price, item[0].Company);
            }
            Console.WriteLine("------商品展示完毕------\n");
        }
    }
}